package test;

import java.util.ArrayList;

public class UserTest2 {
    public static void main(String[] args) {
        ArrayList<User> list = new ArrayList<>();

        User u1 = new User("heima001","zhangsan","123456");
        User u2 = new User("heima002","lisi","12345678");
        User u3 = new User("heima003","wangwu","123456qwer");

        list.add(u1);
        list.add(u2);
        list.add(u3);

        int falg = getIndex(list, "heima003");

        System.out.println(falg);
    }

    public static int getIndex(ArrayList<User> list,String id){
        for (int i = 0; i < list.size(); i++) {
            User u = list.get(i);
            String uid = u.getId();
            if(uid.equals(id)){
                return i;
            }
        }
        return -1;
    }
}
